package com.twt.service;

import com.twt.Dao.ThrowLakeDao;
import com.twt.Dao.UserDao;
import com.twt.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@Transactional(rollbackFor = RuntimeException.class)
public class ThrowLakeService {

    @Autowired
    private ThrowLakeDao throwLakeDao;

    /**
     * 投湖
     *
     * @param username,context 参数封装
     * @return Result
     */

    public Result throwLake(String username, String context) {
        Result result = new Result();
        result.setSuccess(false);
        result.setDetail(null);
        SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//设置日期格式
        String Time = df.format(new Date());// new Date()为获取当前系统时间
        String nickname = throwLakeDao.findNicknameByUsername(username);
        //直接插到lake表里面
        throwLakeDao.throwLake(nickname, username, context,Time);
        result.setMsg("投湖成功");
        result.setSuccess(true);
        result.setDetail(null);
        return result;
    }
}
